﻿// --------------------------------------------------------------------------------------------------------------------- 
// <copyright file="Problem12.cs" company="Microsoft">
//   Copyright (c) Microsoft Corporation.  All rights reserved. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// </copyright>
// <summary>
//   Defines the Problem12 type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------
namespace EulerProblemsCSharp.Problems
{
    using System;
    using System.Linq;

    /// <summary>
    /// Problem 12.
    /// </summary>
    public class Problem12 : ProblemBase
    {
        /// <summary>
        /// Gets Number.
        /// </summary>
        /// <value>
        /// The number.
        /// </value>
        public override int Number
        {
            get
            {
                return 12;
            }
        }

        /// <summary>
        /// Gets Description.
        /// </summary>
        /// <value>
        /// The description.
        /// </value>
        public override string Description
        {
            get
            {
                return "What is the value of the first triangle number to have over five hundred divisors?";
            }
        }

        /// <summary>
        /// Solves the problem.
        /// </summary>
        /// <returns>
        /// Solution to the problem.
        /// </returns>
        public override object Solve()
        {
            var query = from triangle in new TriangleNumbers().Sequence
                        where triangle.GetDivisors().Distinct().Count() > 500
                        select triangle;

            var answer = query.First();
            return answer;                      
        }
    }
}